import axios from 'axios'
import { remoToken } from './storage'
// 获取token
import { getToken } from '../api/storage'
import {  Toast } from 'antd-mobile'
axios.defaults.timeout = 1000 * 60*15
axios.defaults.baseURL = 'http://localhost:5001'
// 请求拦截
axios.interceptors.request.use(
    request => {
        let token = getToken()
        if(token) {
            request.headers.Authorization = getToken()
            // request.url.startsWith 
        }
 Toast.show({
		icon: 'loading',
		content: '加载中…',
 })
        return request
    },
    err => {
        Promise.reject(err)
        
    }
)

// 响应拦截器
axios.interceptors.response.use(
    response => {
        console.log(response)
        if (response.data.status === 400) {
            remoToken()
            window.location.href = '/login'
             Toast.show({
					icon: 'loading',
					content: '暂未登录，请先登录',
				})
        }
        Toast.clear()
        return response.data
    },
    err => {
        // console.log('响应出错了',err)
    }
)

export default axios